﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;

namespace Ymatou.File.Lib
{
    public class ValidateAuthorizeAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext authContext)
        {
            string validateKey = "";

            if(authContext.RouteData.Values["bhkey"] != null)
            {
                validateKey = authContext.RouteData.Values["bhkey"].ToString();
            }

            if (authContext.RequestContext.HttpContext.Request.QueryString["bhkey"] != null)
            {
                validateKey = authContext.RequestContext.HttpContext.Request.QueryString["bhkey"];
            }  

            if(validateKey != FileHelper.ValidateKey)
            {
                authContext.Result = new ContentResult() { Content = "Error:验证码错误"};
            }
        }
    }
}